package com.education.welco.service.impl;

import com.education.common.utils.Convert;
import com.education.welco.mapper.PlatResourceShareMapper;
import com.education.welco.pojo.PlatResourceShare;
import com.education.welco.pojo.PlatformResources;
import com.education.welco.pojo.vo.ShareSchoolVo;
import com.education.welco.service.IPlatResourceShareService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 平台资源共享 服务层实现
 *
 * @Author: liftsail
 * @Date: 2022-09-28
 * @Description: 不积跬步无以至千里
 */
@Service
public class PlatResourceShareServiceImpl implements IPlatResourceShareService {

    @Autowired
    private PlatResourceShareMapper platResourceShareMapper;

    /**
     * 查询平台资源共享信息
     *
     * @param id 平台资源共享ID
     * @return 平台资源共享信息
     */
    @Override
    public PlatResourceShare selectPlatResourceShareById(Integer id) {
        return platResourceShareMapper.selectPlatResourceShareById(id);
    }

    /**
     * 查询平台资源共享列表
     *
     * @param platResourceShare 平台资源共享信息
     * @return 平台资源共享集合
     */
    @Override
    public List<PlatResourceShare> selectPlatResourceShareList(PlatResourceShare platResourceShare) {
        return platResourceShareMapper.selectPlatResourceShareList(platResourceShare);
    }

    /**
     * 新增平台资源共享
     *
     * @param platResourceShare 平台资源共享信息
     * @return 结果
     */
    @Override
    public int insertPlatResourceShare(PlatResourceShare platResourceShare) {
        platResourceShare.setCreateTime(new Date());
        return platResourceShareMapper.insertPlatResourceShare(platResourceShare);
    }

    /**
     * 修改平台资源共享
     *
     * @param platResourceShare 平台资源共享信息
     * @return 结果
     */
    @Override
    public int updatePlatResourceShare(PlatResourceShare platResourceShare) {
        return platResourceShareMapper.updatePlatResourceShare(platResourceShare);
    }

    /**
     * 删除平台资源共享对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePlatResourceShareByIds(String ids) {
        return platResourceShareMapper.deletePlatResourceShareByIds(Convert.toStrArray(ids));
    }

    @Override
    public List<ShareSchoolVo> selectShareSchoolList() {
        return platResourceShareMapper.selectShareSchoolList();
    }

    @Override
    public PlatResourceShare selectPlatResourceShareByShareIdAndResIdAndReceiveId(Integer sharerId, String resId, Integer receiverId) {
        return platResourceShareMapper.selectPlatResourceShareByShareIdAndResIdAndReceiveId(sharerId, resId, receiverId);
    }

    @Override
    public int updatePlatResourceShareByShareIdAndResIdAndReceiveId(PlatResourceShare platResourceSharecp) {
        return platResourceShareMapper.updatePlatResourceShareByShareIdAndResIdAndReceiveId(platResourceSharecp);
    }

    @Override
    public List<PlatResourceShare> selectPlatResourceShareByResIdAndisDelete(List<String> resIdList, boolean isDelete) {
        return platResourceShareMapper.selectPlatResourceShareByResIdAndisDelete(resIdList, isDelete);
    }

    @Override
    public List<PlatResourceShare> selectPlatResourceShareByShareIdAndResIdListAndReceiveId(Integer sharerId, List<String> resIdList, Integer receiverId) {
        return platResourceShareMapper.selectPlatResourceShareByShareIdAndResIdListAndReceiveId(sharerId, resIdList, receiverId);
    }

    @Override
    public int batchUpdatePlatResourceShareByShareIdAndResIdListAndReceiveId(Integer sharerId, List<String> resIdListBefore, Integer receiverId, boolean isDelete) {
        return platResourceShareMapper.batchUpdatePlatResourceShareByShareIdAndResIdListAndReceiveId(sharerId, resIdListBefore, receiverId, isDelete);
    }

    @Override
    public int batchInsertPlatResourceShareByShareIdAndResIdListAndReceiveId(Integer sharerId, List<String> resIdListUserNow, Integer receiverId, boolean isDelete) {
        return platResourceShareMapper.batchInsertPlatResourceShareByShareIdAndResIdListAndReceiveId(sharerId, resIdListUserNow, receiverId, isDelete);
    }

    @Override
    public List<PlatformResources> selectShareSchoolResListBySharerId(Integer sharerId, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<PlatformResources> platformResourcesList = platResourceShareMapper.listTheDirForShareListAndSchoolByUserId(sharerId);
        return platformResourcesList;
    }

    @Override
    public List<PlatformResources> selectShareSchoolResListBySchoolId(Integer schoolId, Integer teaId, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        return platResourceShareMapper.selectShareSchoolResListBySchoolId(schoolId,teaId);
    }
}